import { useRequest } from "../../../utils/request";

const WeValidator = require('../../../package/we-validator.min')

Component({
    properties: {},
    data: {
        textLength: 0,
    },
    methods: {
        onLoad() {
            this.validatorInstance = new WeValidator({
                rules: {
                    description: {
                        required: true,
                    }
                },
                messages: {
                    description: {
                        required: '请输入反馈内容',
                    }
                },
            })
            this.request = new useRequest('api/userpostfeedback', {
                hold: true
            }, this)
        },
        textInput(e) {
            const cursor = e.detail.cursor
            this.setData({
                textLength: cursor > 200 ? 200 : cursor
            })
        },
        submit(e) {
            const value = e.detail.value

            if (this.validatorInstance.checkData(value)) {
                this.request
                    .run(value)
                    .then(() => {
                        wx.showToast({
                            title: '反馈成功'
                        })
                        wx.navigateBack()
                    })
            }
        }
    }
});
